<template>
	<view class="main">
		<u-navbar
			title="企业视频"
			@leftClick="navigateBack"
			safeAreaInsetTop
			fixed
			placeholder
			:autoBack="true"
		></u-navbar>
		<view class="block">
			<view class="block__content">
				<u--form
					labelPosition="left"
					:model="info"
					ref="form"
				>
					<u-form-item
						label="视频"
						prop="video"
					>
					<view style="display:flex; justify-content: right;color:blue;" @click="upload">选择视频</view>
					</u-form-item>
					
					<u-form-item
						label=""
						prop="video"
					>
					<video :src="imgURL + info.video"></video>
					</u-form-item>
					<u-form-item
						label=""
						prop="video_remark"
					>
						<u--textarea
							placeholder="视频简介不低于3个字"
							v-model="info.remark"
							count
							:maxlength='800'
						></u--textarea>
					</u-form-item>
				</u--form>
				<u-button
					type="primary"
					text="提交"
					customStyle="margin-top: 50px"
					@click="submit"
				></u-button>
			</view>
		</view>
	</view>
</template>

<script>
	import util from "@/utils/utils.js"
	import { myenterprise,saveBasic } from '@/api/enterprise.js'
	import { imgURL } from '@/utils/config'
	export default {
		data() {
			return {
				imgURL:imgURL,
				info:{}
			}
		},
		onLoad() {
			this.getEnterprise()
		},
		methods: {
			//提交参数
			getEnterprise() {
				myenterprise({}).then(res=>{
					if(res.code == 200){
						this.info = res.data
					}
					else{
						return uni.showToast({
							icon: 'none',
							title: res.msg
						});
					}
				})
			},
			
			//提交参数
			submit() {
				
				if (this.info.video == "") {
					return uni.showToast({
						icon: 'none',
						title: '请上传视频'
					});
				}
				if (this.info.video_remark == "") {
					return uni.showToast({
						icon: 'none',
						title: '请填写视频简介'
					});
				}
			
				saveBasic(this.info).then(res=>{
					if(res.code == 200){
						uni.showToast({
							title:res.msg,
							duration: 2000,
							icon:'none',
							success() {
								console.log(res)
								uni.redirectTo({
									url: '/pages/enterprise/resume'
								});
							}
						});
					}
					else{
						return uni.showToast({
							icon: 'none',
							title: res.msg
						});
					}
				})
			},
			
			// 上传视频
			async upload() {
				let _this = this;
				util.chooseVideo("/user/video").then((res)=>{
					if(res.code == 200){
						uni.showToast({
							title:res.msg,
							duration: 2000,
							icon:'none',
							success() {
								_this.info.video = res.data
							}
						});
					}
					else{
						return uni.showToast({
							title:res.msg,
							duration: 2000,
							icon:'none'
						});
					}
				})
			},
		},
	}
</script>

<style lang="scss">
	.main{
		margin: 50rpx;
	}
</style>
